n, m = map (int, input().split())
rub = list (map (int, input().split()))
sap = list (map (int, input().split()))
fst = False snd = False
for r in rub:
rbest = r * sap[0] for s in sap:
rbest = max (rbest, r * s)
if fst == False:
fst = rbest
elif rbest > fst:
snd = fst
fst = rbest
elif snd == False or rbest > snd:
snd = rbest
print (snd)
#include <bits/stdc++.h>
using namespace std;
#define TESTCASES false
void solve(int tt) {
int n, m;
cin >> n >> m;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
vector<pair<long long, int>> comb(n * m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
comb[(i * m) + j] = {a[i] * b[j], i};
}
}
sort(comb.rbegin(), comb.rend());
int i = 1;
while (i < comb.size() && comb[i].second == comb[0].second)
i++;
if (i == comb.size())
i--;
cout << comb[i].first << "\n";
}
int main() {
if (!TESTCASES) {
solve(0);
return 0;
}
int t;
cin >> t;
for (int i = 0; i < t; i++) {
solve(i + 1);
}
return 0;
}
921. Minimum Add to Make Parentheses Valid | 881. Boats to Save People |
497. Random Point in Non-overlapping Rectangles | 528. Random Pick with Weight |
470. Implement Rand10() Using Rand7() | 866. Prime Palindrome |
1516A - Tit for Tat | 622. Design Circular Queue |
814. Binary Tree Pruning | 791. Custom Sort String |
787. Cheapest Flights Within K Stops | 779. K-th Symbol in Grammar |
701. Insert into a Binary Search Tree | 429. N-ary Tree Level Order Traversal |
739. Daily Temperatures | 647. Palindromic Substrings |
583. Delete Operation for Two Strings | 518. Coin Change 2 |
516. Longest Palindromic Subsequence | 468. Validate IP Address |
450. Delete Node in a BST | 445. Add Two Numbers II |
442. Find All Duplicates in an Array | 437. Path Sum III |
436. Find Right Interval | 435. Non-overlapping Intervals |
406. Queue Reconstruction by Height | 380. Insert Delete GetRandom O(1) |
332. Reconstruct Itinerary | 368. Largest Divisible Subset |